// pages/rentCar/rentCar.js
let app = getApp()
let request = require('../../utils/request.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageAllHeight: app.globalData.pageAllHeight,
    callPhoneDialog: false,
    phoneNumber: '',
    monthCarList: [],
    currentPage: 1,
    pageSize: 15,
    pageFlag: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMonthCar()
  },
  /**
   * 获取全部月租车辆
   */
  getMonthCar(next) {
    request.http(
      '/customer/card/getMonthCarList',
      'GET', 
      { parkId: wx.getStorageSync('parkInfo').parkId }
    ).then(res => {
        let data = res.data
        if (data.code == 200) {
          this.setData({ monthCarList: data.data })
        }
      })
  },
  /**
  * 打开拨号弹窗
  */
  showCallPhoneDialog(e) {
    this.setData({
      callPhoneDialog: true,
      phoneNumber: e.target.dataset.phone
    })
  },
  /**
   * 关闭拨号弹窗
   */
  hiddenCallPhoneDialog() {
    this.setData({
      callPhoneDialog: false
    })
  },
  /**
   * 拨打电话
   */
  callPhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.phoneNumber,
    })
    this.hiddenCallPhoneDialog()
  },
  /**
 * 触底事件
 */
  scrollTolower() {
    if (this.data.pageFlag) {
      return
    }
    this.setData({
      pageFlag: true,
      currentPage: this.data.currentPage + 1
    })
    this.getMonthCar(true)
  }
})